var prefix = jsctx + "/shopOrder";

var shopOrdereds = (function (v) {
    function init(v) {
        setTimeout(function () {//防止先于-读取缓存执行
            load(v);
        }, 10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 120;

    function load(k) {

        var transferType = $("#transferType").val();
        var isVerification = $("#isVerification").val();

        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'GET',
                    url: prefix + "/listShopOrder",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    // cache: false,
                    pageSize: 10,
                    pageList: [10, 20, 30],
                    pageNumber: 1,
                    sidePagination: "server",
                    paginationShowPageGo: true,
                    // contentType : "application/x-www-form-urlencoded",
                    // rightFixedColumns: true,
                    height: h,
                    queryParams: function (params) {

                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            goodsName: $("#goodsName").val().trim(),
                            shopOrderNum: $("#shopOrderNum").val().trim(),
                            salePlatform: $("#salePlatform").val().trim(),
                            saleType: $("#saleType").val().trim(),
                            // outTradeNo: $("#outTradeNo").val().trim(),
                            // refundBy: $("#refundBy").val().trim(),
                            // memberMobile: $("#memberMobile").val().trim(),
                            // memberRealName: $("#memberRealName").val().trim(),
                            status: $("#status").val().trim(),
                            startTime: $("#startTime").val().trim(),
                            endTime: $("#endTime").val().trim(),
                            shippingMobile: $("#shippingMobile").val(),
                            shippingPerson:$("#shippingPerson").val().trim(),

                        };
                    },
                    columns: [

                        {
                            title: '#', field: '', width: '50', align: 'center',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'nickname', title: '用户昵称', align: 'center', width: '100'},
                        {field: 'mobile', title: '手机号', align: 'center', width: '100'},
                        {field: 'goodsImage', title: '商品缩略图', width: '200', align: 'left',
                            formatter:function (value, row, index) {
                                var z = ''
                                z = '<img  src="'+k+value+'" >'
                                return z;
                            }

                        },
                        {field: 'goodsName', title: '商品名称', width: '110', align: 'center'},
                        {field: 'salePlatform', title: '兑换方式', width: '80', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '线上'
                                } else if (value == '1') {
                                    return '线下'
                                } else if (value == '2') {
                                    return '快递邮寄'
                                }
                            }
                        },
                        {field: 'shopOrderNum', title: '订单号', width: '110', align: 'center'},
                        {field: 'goodsPoint', title: '积分单价', width: '80', align: 'center'},
                        {field: 'goodsPrice', title: '实际单价（元）', width: '80', align: 'center'},
                        {field: 'goodsNum', title: '兑换数量', width: '80', align: 'center'},

                        {field: 'saleType', title: '支付方式', width: '100', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '积分兑换'
                                } else if (value == '1') {
                                    return '人民币购买'
                                } else if (value == '2') {
                                    return '积分,人民币'
                                }
                            }},
                        {field: 'payAmount', title: '实付', width: '120', align: 'center',
                            formatter: function (value, row, index) {
                                if (row.saleType == '0') {
                                    return parseInt(row.goodsPoint * row.goodsNum)
                                } else if (row.saleType == '1') {
                                    return value
                                }
                            }
                        },

                        {field: 'shippingPerson', title: '收货人', width: '80', align: 'center'},
                        {field: 'shippingMobile', title: '联系电话', width: '80', align: 'center'},
                        {field: '', title: '收货地址', width: '80', align: 'center',
                           formatter:function (value,row,index) {
                        //     if (row.provinceName == null){
                        //         if (row.cityName == null){
                        //             if (row.areaName == null){
                        //                 if ()
                        //             }
                        //             else{
                        //                 return row.areaName + row.shippingAddress
                        //             }
                        //         }
                        //         else if(row.areaName == null){
                        //             row.
                        //         }
                        //         else if ()
                        //
                        //     }
                        //     else {
                        //         return row.provinceName + row.cityName + row.areaName + row.shippingAddress
                        //
                        // }
                               if (row.provinceName == null){
                                   row.provinceName = ''
                               }
                               if (row.cityName == null){
                                   row.cityName = ''
                               }
                               if (row.areaName == null){
                                   row.areaName = ''
                               }
                               if (row.shippingAddress == null){
                                   row.shippingAddress = ''
                               }
                               return row.provinceName + row.cityName + row.areaName + row.shippingAddress
                            }},
                        {field: 'shippingNo', title: '快递单号', width: '80', align: 'center'},
                        {field: 'deliverExpress', title: '快递公司', width: '80', align: 'center'},
                        {field: 'returnShippingNo', title: '退货快递单号', width: '80', align: 'center'},
                        {field: 'returnExpress', title: '退货快递公司', width: '80', align: 'center'},
                        {field: 'createdTime', title: '下单时间', width: '80', align: 'center'},
                        {field: 'status', title: '订单状态', width: '80', align: 'center',
                            // 订单状态 0未付款 1已付款未发货 2已发货 3已收货 4已取消 5退货申请中 6等待退回 7退货成功 默认0
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '未付款'
                                } else if (value == '1') {
                                    if(row.salePlatform == '1'){
                                        return '待使用'
                                    } else {
                                        return '待发货'
                                    }
                                } else if (value == '3') {
                                    return '已收货'
                                }else if (value == '2') {
                                    return '待收货'
                                }else if (value == '4') {
                                    return '已取消'
                                }else if (value == '5') {
                                    return '退货申请中'
                                }else if (value == '6') {
                                    return '等待退回'
                                }else if (value == '7') {
                                    return '退货成功'
                                }

                            }
                        },
                        {field: 'receiverTime', title: '完成时间', width: '80', align: 'center',
                            formatter: function (value, row, index) {
                                if (row.status == '3' || row.status == '7') {
                                    return row.lastUpdatedTime
                                }else{
                                    return ''
                                }
                            }
                        },
                        {field: 'rejectRemark', title: '备注', width: '100', align: 'center'},

                        // {field: 'remark', title: '失败原因', width: '100', align: 'left'},
                        {

                            field: 'roleId',
                            title: '操作',
                            width: '200', align: 'center',
                            // class: 'operate-td',
                            formatter: function (value, row, index) {
                                var a = '';
                                var b = '';
                                var c = '';
                                var e = '';



                                // g =' <a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="通过" onclick="shopOrdered.updateStatusForPassVerification()">补货</a>'
                                a = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="通过" onclick="shopOrdereds.updateStatusForPass(\''
                                    // + row.goodsName + '\',' + '\'' + row.goodsId
                                    + row.shopOrderId
                                    + '\')">发货</a> ';
                                e = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="通过" onclick="shopOrdereds.updateStatusForPassVerification(\''
                                    + row.shopOrderId + '\',' + '\'' + row.goodsName + '\',' + '\'' + row.shopOrderNum

                                    + '\')">驳回</a> ';
                                b = '<a class="btn btn-danger btn-sm ' + has_edit + '" href="#" title="" onclick="shopOrdereds.updateStatusForOverrule(\''
                                    + row.shopOrderId + '\',' + '\'' + row.goodsName + '\',' + '\'' + row.shopOrderNum
                                    + '\')">确认收货</a> ';


                                c = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="详情" onclick="shopOrdereds.getMemberRefundApplyDetail(\''
                                    + row.shopOrderId + '\',' + '\'' + row.goodsName + '\',' + '\'' + row.shopOrderNum
                                    + '\')">退货已收</a> ';

                                var d = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="已到账" onclick="shopOrdereds.updateStatusForArrive(\''
                                    + row.shopOrderId + '\',' + '\'' + row.goodsName + '\',' + '\'' + row.shopOrderNum
                                    + '\')">通过</a> ';

                             if (row.status == '1'){
                                 if (row.salePlatform=='1'){
                                     return '';
                                 }
                                 return a;
                             }
                             else if (row.status == '2'){
                                 return b;
                             }
                             else if (row.status == '5'){
                                 return d+e;
                             }
                             else if (row.status == '6'){
                                 return c + e;
                             }
                            }
                        }
                    ]
                });
    }
    function reLoad() {
        // $(".fixed-table-header-columns").css("display", "none");
        // $(".fixed-table-body-columns").css("display", "none");
        $('#exampleTable').bootstrapTable('refresh');
    }

    function addMemberRefundApply() {
        location.href = jsctx + "/templates/shopGoods/addShop.jsp"
    }
    function editGoods(goodsId) {
        location.href = jsctx + "/templates/shopGoods/shopGoodsEdit.jsp?goodsId="+goodsId
    }

        function getMemberRefundApplyDetail(shopOrderId,goodsName,shopOrderName) {
            var charge = shopOrderId;
            var chat = goodsName;
            var chated = shopOrderName;
            var html = "<div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:18px'>商品名称：</div><span style='font-size: 18px'>"+ chat +"</span></div><div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:18px'>订单号：</div><span style='font-size: 18px'>"+ chated +"</span></div><div style='font-size:20px;width:90%;margin-left:15px;margin-top:15px'>温馨提示：已收到退货物品，确认后订单消费将退回用户账户，是否确认？</div>"
            var index = layer.open({
                    type:1,
                    title:'退回已收',
                    btn:['确认'],
                    area:['400px','280px'],
                    content:html,
                    // btn2: function () {
                    //     alert("取消按钮")
                    //     layer.close(index);
                    //     reLoad();
                    //     // }
                    // },
                yes:function () {
                        $.ajax({
                            url: prefix + "/updateShopOrderStatus",
                            type: "POST",
                            data: {
                                'shopOrderId': charge,
                                'method':3
                            },
                            beforeSend: function () {
                                // isajaxsendForPass = true;
                            },
                            success: function (data) {
                                // isajaxsendForPass = true;
                                layer.close(index);
                                if (data.status == 200) {
                                    layer.msg("处理成功");
                                    reLoad();
                                } else {
                                    // isajaxsendForPass = true;
                                    layer.msg(data.message);
                                    reLoad();
                                }
                            }
                        });
                    }
                }
            )


    }

    var isajaxsendForPass = true;
    function downdateStatusForPass(goodsName,goodsId) {
        var charge = goodsId;
        var chat = goodsName;

        var html = "<div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:18px'>商品名称：</div><span style='font-size: 18px'>"+ chat +"</span></div><div style='font-size:18px;width:90%;margin-left:15px;margin-top:15px'>温馨提示：商品上架后，用户可在手机端兑换该商品，商品对应信息不可编辑，只能调整货物数量，是否确认上架？</div>"
        var index = layer.open({
                type:1,
                title:'商品上架',
                btn:['确认'],
                area:['400px','250px'],
                content:html,
                // yes: function () {
                //     layer.close();
                //     reLoad();
                //     // }
                // },
                yes:function () {
                    // alert(1)
                    // if (!isajaxsendForPass) {
                    $.ajax({
                        url: prefix + "/saveOrUpdateShopOrder",
                        type: "POST",
                        data: {
                            'goodsId': charge,
                            'status':'1'

                        },
                        beforeSend: function () {
                            // isajaxsendForPass = true;
                        },
                        success: function (data) {
                            // isajaxsendForPass = true;
                            layer.close(index);
                            if (data.status == 200) {
                                layer.msg("处理成功");
                                reLoad();
                            } else {
                                // isajaxsendForPass = true;
                                layer.msg(data.message);
                                reLoad();
                            }
                        }
                    });
                }
            }
        )
    }
    function updateStatusForPass(shopOrderId) {
        var charge = shopOrderId;

        var html = "<div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:15px'>快递单号</div><div style='margin-left:15px;display:inline-block;'><input id='future' type='text' style='width: 250px' value=''></div></div><div style='margin-top: 15px;'><div style='display:inline-block;font-size:15px;margin-left:15px;margin-top:15px'>快递公司</div><div style='margin-left:15px;display:inline-block;'><input id='future2' type='text' style='width: 250px' value=''></div></div>"
        var index = layer.open({
                type:1,
                title:'填写发货信息',
                btn:['确认'],
                area:['400px','200px'],
                content:html,
                //
                //
                //
                // yes: function () {
                //     layer.close();
                //     reLoad();
                //     // }
                // },
                yes:function () {
                    // alert(1)
                    // if (!isajaxsendForPass) {
                    $.ajax({
                        url: prefix + "/updateShopOrderInfo",
                        type: "POST",
                        data: {
                            'shopOrderId':charge,
                             'shippingNo':$('#future').val(),
                            'deliverExpress':$('#future2').val()

                        },
                        beforeSend: function () {
                            // isajaxsendForPass = true;
                        },
                        success: function (data) {
                            // isajaxsendForPass = true;
                            layer.close(index);
                            if (data.status == 200) {
                                layer.msg("处理成功");
                                reLoad();
                            } else {
                                // isajaxsendForPass = true;
                                layer.msg(data.message);
                                reLoad();
                            }
                        }
                    });
                }
            }
        )
    }


        function updateStatusForPassVerification(shopOrderId,goodsName,shopOrderName) {
            var charge = shopOrderId;
            var chat = goodsName;
            var chated = shopOrderName
            var html = "<div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:18px'>商品名称：</div><span style='font-size: 18px'>"+ chat +"</span></div><div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:18px'>订单号：</div><span style='font-size: 18px'>"+ chated +"</span></div><div style='font-size:20px;width:90%;margin-left:15px;margin-top:15px'>驳回请及时告知用户具体原因</div><div style='margin-top:15px;'><div style='display:inline-block;margin-top:15px;font-size:18px;margin-left:15px;vertical-align:top;'>驳回理由</div><div style='display:inline-block;vertical-align:top;margin-left:15px;'><textarea name='' id='reasons' cols='30' rows='5'></textarea></div></div>"
            var index = layer.open({
                    type:1,
                    title:'驳回退货申请',
                    btn:['确认'],
                    area:['400px','350px'],
                    content:html,
                    //
                    //
                    //
                    // yes: function () {
                    //     layer.close();
                    //     reLoad();
                    //     // }
                    // },
                yes:function () {
                        // alert(1)
                        // if (!isajaxsendForPass) {
                        $.ajax({
                            url: prefix + "/updateShopOrderStatus",
                            type: "POST",
                            data: {
                                'shopOrderId': charge,
                                'method':2,
                                'remark':$('#reasons').val()
                            },
                            beforeSend: function () {
                                // isajaxsendForPass = true;
                            },
                            success: function (data) {
                                // isajaxsendForPass = true;
                                layer.close(index);
                                if (data.status == 200) {
                                    layer.msg("处理成功");
                                    reLoad();
                                } else {
                                    // isajaxsendForPass = true;
                                    layer.msg(data.message);
                                    reLoad();
                                }
                            }
                        });
                    }
                }
            )

        }



    function updateStatusForOverrule(shopOrderId,goodsName,shopOrderName) {
        var charge = shopOrderId;
        var chat = goodsName;
        var chated = shopOrderName
        var html = "<div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:18px'>商品名称：</div><span style='font-size: 18px'>"+ chat +"</span></div><div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:18px'>订单号：</div><span style='font-size: 18px'>"+ chated +"</span></div><div style='font-size:20px;width:90%;margin-left:15px;margin-top:15px'>温馨提示：确认收货请核对订单号是否正确，收货后不可更改，是否确认收货？</div>"
        var index = layer.open({
                type:1,
                title:'确认收货',
                btn:['确认'],
                area:['400px','280px'],
                content:html,
                // yes: function () {
                //     layer.close();
                //     reLoad();
                //     // }
                // },
                yes:function () {
                    // alert(1)
                    // if (!isajaxsendForPass) {
                    $.ajax({
                        url: prefix + "/updateShopOrderStatus",
                        type: "POST",
                        data: {
                            'shopOrderId': charge,
                            'method':0
                        },
                        beforeSend: function () {
                            // isajaxsendForPass = true;
                        },
                        success: function (data) {
                            // isajaxsendForPass = true;
                            layer.close(index);
                            if (data.status == 200) {
                                layer.msg("处理成功");
                                reLoad();
                            } else {
                                // isajaxsendForPass = true;
                                layer.msg(data.message);
                                reLoad();
                            }
                        }
                    });
                }
            }
        )
    }


    /*------  验证码  -----*/
    var num1 = 60;
    var ajaxReady = true;

    function getMemberRefundAuthCode() {
        if (ajaxReady) {
            $.ajax({
                url: prefix + "/getMemberRefundAuthCode",
                type: "POST",
                data: $('#authCode').val(),
                beforeSend: function () {
                    ajaxReady = false;
                },
                success: function (data) {
                    if (data.status == 200) {
                        time();

                        function time() {
                            if (num1 == 0) {
                                // $('#authCode').attr("disabled", "disabled")
                                $('#getMemberRefundAuthCode').text("获取验证码");
                                $('#getMemberRefundAuthCode').attr("onclick", 'memberRefundApply.getMemberRefundAuthCode()');
                                ajaxReady = true;
                                num1 = 60;
                            } else {
                                // $('#authCode').removeAttr('disabled')
                                $('#getMemberRefundAuthCode').html(num1 + "秒后重试");
                                $('#getMemberRefundAuthCode').removeAttr('onclick');
                                num1--;
                                setTimeout(function () {
                                    time()
                                }, 1000)
                            }
                        }
                    } else {
                        parent.layer.alert(data.message);
                        $('#authCode').removeAttr('disabled')
                        $('#getMemberRefundAuthCode').text("获取验证码");
                        $('#getMemberRefundAuthCode').attr("onclick", 'memberRefundApply.getMemberRefundAuthCode()');
                        ajaxReady = true;
                        num1 = 60;
                    }

                }
            })


        }
    };

    var isajaxsendForArrive = true;


        function updateStatusForArrive(shopOrderId,goodsName,shopOrderName) {
            var charge = shopOrderId;
            var chat = goodsName;
            var chated = shopOrderName
            var html = "<div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:18px'>商品名称：</div><span style='font-size: 18px'>"+ chat +"</span></div><div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:18px'>订单号：</div><span style='font-size: 18px'>"+ chated +"</span></div><div style='font-size:20px;width:90%;margin-left:15px;margin-top:15px'>温馨提示：通过后请联系用户及时发货，并保证货物完好。是否确认通过？</div>"
            var index =  layer.open({
                    type:1,
                    title:'通过退货申请',
                    btn:['确认'],
                    area:['400px','280px'],
                    content:html,
                    // yes: function () {
                    //     layer.close();
                    //     // }
                    // },
                // btn2:function(){
                //     alert(888)
                // },
                    yes:function () {
                        $.ajax({
                            url: prefix + "/updateShopOrderStatus",
                            type: "POST",
                            data: {
                                'shopOrderId': charge,
                                'method':1
                            },
                            beforeSend: function () {
                                // isajaxsendForPass = true;
                            },
                            success: function (data) {
                                // isajaxsendForPass = true;
                                layer.close(index);
                                if (data.status == 200) {
                                    layer.msg("处理成功");
                                    reLoad();
                                } else {
                                    // isajaxsendForPass = true;
                                    layer.msg(data.message);
                                    reLoad();
                                }
                            }
                        });
                    }
                }
            )

    }

    function goBack() {
        window.history.back();
    }

    function exportMemberRefundApply() {
        $.fileDownload(prefix + "/exportMemberRefundApply", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                nickname: $("#nickname").val().trim(),
                mobile: $("#mobile").val().trim(),
                refundSource: $("#refundSource").val().trim(),
                outTradeNo: $("#outTradeNo").val().trim(),
                refundBy: $("#refundBy").val().trim(),
                memberMobile: $("#memberMobile").val().trim(),
                memberRealName: $("#memberRealName").val().trim(),
                status: $("#status").val().trim(),
                startTime: $("#startTime").val().trim(),
                endTime: $("#endTime").val().trim(),
                count: $("#count").val().trim() == '' ? 0 : $("#count").val().trim(),
                offset: $('.active .page-link').text(),
                limit: $(".page-size").text()
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    }
    function pdselect(){
        $.ajax({
            url: prefix + "/updateShopVerificationCode",
            type: "GET",
            data: {
            },
            beforeSend: function () {
                // isajaxsendForPass = true;
            },
            success: function (data) {
                // isajaxsendForPass = true;
                console.log(data);
                layer.close();
                if (data.status == 200) {
                    // layer.msg("处理成功");
                    var futureTime = data.message;
                    // reLoad();
                    var html = "<div style='font-size:18px;width:90%;margin-left:15px;margin-top:15px'>您的商品核销码为随机生成，线下兑换的商品请相关工作人员核销订单</div><div style='font-size: 20px;font-weight: bolder;text-align: center;margin-top: 25px;'>"+ futureTime +"</div>"
                    var index = layer.open({
                            type:1,
                            title:'商品核销码',
                            btn:['刷新','确认'],
                            area:['400px','250px'],
                            content:html,
                            yes: function () {
                                // layer.closeAll();
                                // reLoad()
                                pdselect();
                            },
                            btn2:function () {
                                layer.close(index);
                            }
                        }
                    )
                } else {
                    // isajaxsendForPass = true;
                    layer.msg(data.message);
                    reLoad();

                }
            }
        });


    }
    function memberAdd(a,b,c,d) {
        isajaxsendForPass = false;
        var number = b.length;
        // var money = c;
        // var money = Math.round(Math.round((c*100)/100));
        var money = Math.floor(c*100) / 100;
        layer.open({
                title:'批量处理',
                area:['300px','200px'],
                content:'勾选数量:'+ number + '</br>'+ '需退款金额:' + money,
                // + '</br>' + '备注:' + '</br>' + '<textarea id="sefix" rows="4" cols="33"></textarea>'
                btn: ['取消','批量处理','批量驳回',],
                yes:function(index,layero){
                    layer.close(index);
                },

                btn2:function(index,layero){
                    // console.log($('#isVerification').val());
                    if($('#isVerification').val() == '0')
                    { $('#exampleModalVerification').modal('show');
                        // console.log($("#sefix").val());
                        // var text = $("#sefix").val();
                        $("#submitVerificationForm").unbind("click").bind("click", function () {
                            var formData = new FormData();
                            formData.append("refundApplyIdsJson",d);
                            formData.append("status", "1");
                            formData.append("authCode", $("#authCode").val());
                            // formData.append("remark", text);
                            var isajaxVerification = true;

                            if (isajaxVerification) {
                                $.ajax({
                                    url: prefix + "/batchUpdateMemberRefundApplyStuts",
                                    type: "post",
                                    data: formData,
                                    dataType: "json",
                                    processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                                    contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                                    beforeSend: function () {
                                        isajaxVerification = false;
                                    },
                                    success: function (data) {

                                        if (data.status == 200 && data.message == "") {
                                            isajaxVerification = true;
                                            parent.layer.msg("操作成功");
                                            $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                                document.getElementById("contentFormVerification").reset();
                                            })
                                            $('#exampleModalVerification').modal('hide');
                                            reLoad();
                                        }
                                        else if(data.status == 200 && data.message != ""){
                                            isajaxVerification = true;
                                            // parent.layer.msg("操作成功");
                                            $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                                document.getElementById("contentFormVerification").reset();
                                            });
                                            $('#exampleModalVerification').modal('hide');
                                            layer.open({
                                                title:'信息提示',
                                                area:['300px','200px'],
                                                content:data.message,
                                                btn: ['确定']

                                            });
                                            reLoad();
                                        }else {
                                            isajaxVerification = true;
                                            parent.layer.alert(data.message);
                                            $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                                document.getElementById("contentFormVerification").reset();
                                            });
                                            $('#exampleModalVerification').modal('hide');
                                            reLoad();
                                        }

                                    }
                                })
                            }

                        })}
                    if($('#isVerification').val() == '1'){
                        var formData = new FormData();
                        formData.append("refundApplyIdsJson",d);
                        formData.append("status", "1");
                        var isajaxVerification = true;
                        if (isajaxVerification) {
                            $.ajax({
                                url: prefix + "/batchUpdateMemberRefundApplyStuts",
                                type: "post",
                                data: formData,
                                dataType: "json",
                                processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                                contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                                beforeSend: function () {
                                    isajaxVerification = false;
                                },
                                success: function (data) {
                                    if (data.status == 200 && data.message == "") {
                                        isajaxVerification = true;
                                        parent.layer.msg("操作成功");
                                        $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                            document.getElementById("contentFormVerification").reset();
                                        })
                                        $('#exampleModalVerification').modal('hide');
                                        reLoad();
                                    }
                                    else if(data.status == 200 && data.message != ""){
                                        isajaxVerification = true;
                                        // parent.layer.msg("操作成功");
                                        $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                            document.getElementById("contentFormVerification").reset();
                                        })
                                        $('#exampleModalVerification').modal('hide');
                                        layer.open({
                                            title:'信息提示',
                                            area:['300px','200px'],
                                            content:data.message,
                                            btn: ['确定']

                                        });
                                        reLoad();
                                    }
                                    else {
                                        isajaxVerification = true;
                                        parent.layer.alert(data.message);
                                        $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                            document.getElementById("contentFormVerification").reset();
                                        })
                                        $('#exampleModalVerification').modal('hide')
                                        reLoad();
                                    }
                                }
                            })}}

                },
                btn3:function(index,layero){

                    $('#exampleModal').modal('show')

                    $("#submitForm").unbind("click").bind("click", function () {

                        var formData = new FormData();
                        formData.append("remark", $("#remark").val());
                        formData.append("refundApplyIdsJson",d);
                        formData.append("status", "2");
                        $.ajax({
                            url: prefix + "/batchUpdateMemberRefundApplyStuts",
                            type: "post",
                            data: formData,
                            dataType: "json",
                            processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                            contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                            success: function (data) {
                                if (data.status == 200 && data.message == "") {
                                    // layer.msg("操作成功");
                                    parent.layer.msg("操作成功");
                                    $('#exampleModal').on('hidden.bs.modal', function () {
                                        document.getElementById("contentForm").reset();
                                    })
                                    $('#exampleModal').modal('hide')
                                    reLoad();
                                }
                                else if(data.status == 200 && data.message != "")
                                {
                                    // layer.msg("请填写备注");
                                    $('#exampleModal').on('hidden.bs.modal', function () {
                                        document.getElementById("contentForm").reset();
                                    })
                                    $('#exampleModal').modal('hide')
                                    layer.open({
                                        title:'信息提示',
                                        area:['300px','200px'],
                                        content:data.message,
                                        btn: ['确定']

                                    })
                                    reLoad();

                                }
                                else {
                                    // layer.msg('操作失败');
                                    parent.layer.alert(data.message);
                                    $('#exampleModal').on('hidden.bs.modal', function () {
                                        document.getElementById("contentForm").reset();
                                    })
                                    $('#exampleModal').modal('hide')
                                    reLoad();
                                }

                            }
                        })
                    })


                }
            }

        )
    }

    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        updateStatusForPass: updateStatusForPass,
        updateStatusForOverrule: updateStatusForOverrule,
        addMemberRefundApply: addMemberRefundApply,
        getMemberRefundApplyDetail: getMemberRefundApplyDetail,
        updateStatusForArrive: updateStatusForArrive,
        exportMemberRefundApply: exportMemberRefundApply,
        updateStatusForPassVerification: updateStatusForPassVerification,
        getMemberRefundAuthCode: getMemberRefundAuthCode,
        memberAdd: memberAdd,
        pdselect:pdselect,
        downdateStatusForPass:downdateStatusForPass,
        editGoods:editGoods
    };
})();

var addMemberRefundApply = (function () {
    function init() {
        validateRule();
    };

    function getCheckedRoles() {
        var adIds = "";
        $("input:checkbox[name=role]:checked").each(function (i) {
            if (0 == i) {
                adIds = $(this).val();
            } else {
                adIds += ("," + $(this).val());
            }
        });
        return adIds;
    }

    var isajaxsend = true;

    function save() {
        if ($("select[name='refundBy']").val() == "2") {
            if ($("select[name='refundBankCode']").val() == "" || $("select[name='refundBankCode']").val() == null) {
                var str = "<label class='error couponError' ><i class='fa fa-times-circle'></i>请选择银行</label>"
                $(".refundBankCodeDiv").append(str)
                return;
            }
        }


        if (isajaxsend) {
            var formData = new FormData($("#frmMemberRefundApply")[0]);
            $("#roleIds").val(getCheckedRoles());
            $.ajax({
                cache: true,
                type: "POST",
                url: prefix + "/saveMemberRefundApply",
                data: formData,
                processData: false,
                contentType: false,
                async: false,
                beforeSend: function () {
                    isajaxsend = false
                },
                error: function (request) {
                    isajaxsend = true
                    parent.layer.alert("Connection error");
                },
                success: function (data) {
                    if (data.status == 200) {
                        isajaxsend = false
                        parent.layer.msg("操作成功");
                        window.history.back();
                    } else {
                        isajaxsend = true
                        parent.layer.alert(data.message)
                    }

                }
            });
        }
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#frmMemberRefundApply").validate({
            rules: {
                // memberMobile: {
                //     required: true
                // },
                // memberRealName: {
                //     required: true
                // },
                refundAmount: {
                    required: true,
                    min: 1
                },
                refundSource: {
                    required: true,
                },

            },
            messages: {
                // memberMobile: {
                //     required: icon + "请输入提现账户号码"
                // },
                // memberRealName: {
                //     required: icon + "请输入真实姓名"
                // },
                refundAmount: {
                    required: icon + "请输入退款金额",
                    min: icon + "请输入大于1的金额",
                },
                refundSource: {
                    required: icon + "请选择用户充电端",
                },
            },
            submitHandler: function (form) {
                save();
            }
        })
    }

    return {
        init: init
    };
})();
